package com.lwl.service.impl.sas;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.dao.sas.TSasPlaneMapper;
import com.lwl.entity.MyPage;
import com.lwl.entity.sas.TSasPlane;
import com.lwl.service.sas.TSasPlaneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TSasPlaneServiceImpl implements TSasPlaneService {
    @Autowired
    private TSasPlaneMapper tSasPlaneDao;

    @Override
    public PageInfo queryAll(MyPage myPage, TSasPlane tSasPlane) {
        PageHelper.startPage(myPage.getPage(), myPage.getLimit());
        List<TSasPlane> tSasPlaneList = tSasPlaneDao.selectAllData(tSasPlane);
        System.out.println("tSasPlaneList*********** = " + tSasPlaneList);
        PageInfo pageInfo = new PageInfo(tSasPlaneList);
        return pageInfo;
    }

    @Override
    public boolean selectCode(TSasPlane tSasPlane) {
        List<TSasPlane> select = tSasPlaneDao.select(tSasPlane);
        return select.size()==0;
    }

    @Override
    public boolean insertPlane(TSasPlane tSasPlane) {
        int insert = -1;
        if (tSasPlane.getId()==null){
            insert = tSasPlaneDao.insert(tSasPlane);
        }else {
            tSasPlane.setUpdatetime(new Date());
            insert = tSasPlaneDao.updateByPrimaryKeySelective(tSasPlane);
        }
        return insert>0?true:false;
    }

    @Override
    public boolean queryByName(String planname) {
////      根据名字查询是否有重名的计划
//      Example example = new Example(TMhtPlane.class);
//      example.createCriteria().andEqualTo("planname",planname);
//      TMhtPlane tMhtPlane = tMhtPlaneDao.selectOneByExample(example);
        List<TSasPlane> tSasPlane1 = tSasPlaneDao.queryOne(planname);
        return tSasPlane1.size()==0?true:false;
    }

    @Override
    public TSasPlane getByCode(TSasPlane tSasPlane) {
        TSasPlane tSasPlane1 = tSasPlaneDao.selectOne(tSasPlane);
        return tSasPlane1;
    }
}
